/*
** xfunc.c for my_irc in /home/billey_b/projet/my_irc
** 
** Made by Bastien Billey
** Login   <billey_b@epitech.net>
** 
** Started on  Fri Apr 13 12:55:38 2012 Bastien Billey
** Last update Mon Apr 16 16:35:02 2012 
*/

#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <stdio.h>
#include <netinet/in.h>
#include <signal.h>
#include <arpa/inet.h>

int	xsocket(int domain, int type, int protocol)
{
  int	sock;

  sock = socket(domain, type, protocol);
  if (sock == -1)
    {
      perror("socket");
      exit(0);
    }
  else
    return sock;
}

int	xbind(int sockfd, struct sockaddr *addr, socklen_t addrlen)
{
  int	n;

  n = bind(sockfd, addr, addrlen);
  if (n == -1)
    {
      perror("bind");
      exit(0);
    }
  else
    return n;
}

int	xconnect(int sockfd, struct sockaddr *addr, socklen_t addrlen)
{
  int	n;

  n = connect(sockfd, addr, addrlen);
  if (n == -1)
    {
      perror("connect");
      exit(0);
    }
  else
    return n;
}

int	xlisten(int sockfd, int backlog)
{
  int	n;

  n = listen(sockfd, backlog);
  if ( n == -1)
    {
      perror("listen");
      exit(0);
    }
  else
    return n;
}

int	xaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
  int	n;

  n = accept(sockfd, addr, addrlen);
  if (n == -1)
    {
      perror("accept");
      exit(0);
    }
  else
    return n;
}
